#include "../include/print.h"
#include "../arch/riscv/include/sbi.h"

void puts(char *s) {
    while (*s) {
        sbi_ecall(SBI_PUTCHAR, 0, *s, 0, 0, 0, 0, 0);
        s++;
    }
}

void puti(int x) {
    char s[16];
    int i = 0;
    if (x == 0) {
        sbi_ecall(SBI_PUTCHAR, 0, '0', 0, 0, 0, 0, 0);
        return;
    }
    if (x < 0) {
        sbi_ecall(SBI_PUTCHAR, 0, '-', 0, 0, 0, 0, 0);
        x = -x;
    }
    while (x) {
        s[i++] = '0' + x % 10;
        x /= 10;
    }
    while (i) {
        sbi_ecall(SBI_PUTCHAR, 0, s[--i], 0, 0, 0, 0, 0);
    }
}
